package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceParam;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/geofence")
public class GeofenceController {
    // 注入业务层
    @Autowired
    private GeofenceService geofenceService;

    /**
     * 查询电子围栏所有信息
     *
     * @param geofenceQuery
     * @return
     */
    @GetMapping("select")
    public JsonResult selectGeofence(GeofenceQuery geofenceQuery) {
        log.debug("查询电子围栏所有信息={}", geofenceQuery);
        List<GeofenceVO> list = geofenceService.selectGeofence(geofenceQuery);
        return JsonResult.ok(list);
    }

    /**
     * 新建电子围栏信息和修改围栏状态
     *
     * @param geofenceParam
     * @return
     */
    @PostMapping("save")
    public JsonResult saveGeofence(GeofenceParam geofenceParam){
        log.debug("保存围栏信息:geofenceParam={}",geofenceParam);
        geofenceService.saveGeofence(geofenceParam);
        return JsonResult.ok();
    }

    /**
     * 删除围栏信息按钮
     * @param geofenceId
     * @return
     */
    @PostMapping("delete/{geofenceId}")
    public JsonResult deleteGeofence(@PathVariable Long geofenceId) {
        log.debug("删除围栏按钮={}", geofenceId);
        geofenceService.deleteGeofence(geofenceId);
        return JsonResult.ok();
    }

}
